Strong typing

Type systems

Type safety
Inferred vs. Manifest
Dynamic vs. Static
Strong vs. Weak
Nominal vs. Structural
Dependent typing
Duck typing
Latent typing
Linear typing
Uniqueness typing

In computer science and computer programming, a type system is said to feature strong typing when it specifies one or more restrictions on how operations involving values of different data types can be intermixed. The opposite of strong typing is weak typing.

Contents

Interpretation

Most generally, "strong typing" implies that the programming language places severe restrictions on the intermixing that is permitted to occur, preventing the compiling or running of source code which uses data in what is considered to be an invalid way. For instance, an addition operation may not be used with an integer and string values; a procedure which operates upon linked lists may not be used upon numbers. However, the nature and strength of these restrictions is highly variable.

Example

Weak Typing Strong Typing
Pseudocode
a = 2
b = "2"
 
concatenate(a, b) # Returns "22"
add(a, b)         # Returns 4
a = 2
b = "2"
 
concatenate(a, b)     # Type Error
add(a, b)             # Type Error
concatenate(str(a), b) # Returns "22"
add(a, int(b))         # Returns 4
Languages Perl, PHP, Rexx, JavaScript, BASIC Java, C, C++, Python, C#, Vala

Meanings in computer literature

Some of the factors which writers have qualified as "strong typing" include:

Variation across programming languages

Note that some of these definitions are contradictory, others are merely orthogonal, and still others are special cases (with additional constraints) of other, more "liberal" (less strong) definitions. Because of the wide divergence among these definitions, it is possible to defend claims about most programming languages that they are either strongly or weakly typed. For instance:

For this reason, writers who wish to write unambiguously about type systems often eschew the term "strong typing" in favor of specific expressions such as "type safety".

See also

References

  1. ^ ftp://gatekeeper.research.compaq.com/pub/DEC/SRC/research-reports/SRC-045.pdf page 3
  2. ^ Cunningham & Cunningham Wiki
  3. ^ Brian Kernighan in Why Pascal is not my favourite language
  4. ^ Infoworld April 25th 1983
  5. ^ Brian Kernighan: Why Pascal is not my favourite language
  6. ^ Common Lisp HyperSpec, Types and Classes
  7. ^ CMUCL User's Manual: The Compiler, Types in Python